<?php

/**
 * Application startup.
 *
 * This file is loaded automatically by the app/webroot/index.php file after core.php
 *
 * This file should load/create any application wide configuration settings, such as 
 * Caching, Logging, loading additional configuration files.
 *
 * You should also use this file to include any files that provide global functions/constants
 * that your application uses.
 *
 * PHP versions 5
 * CAKEPHP versions 2.x
 * 
 * Green CMS - Content Management System and Framework Powerfull by Cakephp
 * Copyright 2012, GREEN GLOBAL CO., LTD (toancauxanh.vn)
 * 
 * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @author        Technology Lab No.I <tech1@toancauxanh.vn>
 * @link          
 * @package       System.Config
 * @since         Green v 1.0
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
App::uses('DebugPerform', 'Configure');
App::uses('Green', 'Utility');
// Include exception class
include APP . 'Lib' . DS . 'exceptions.php';

// Load application config
Configure::load('App');

/**
 * Cache config
 */
if (($duration = Configure::read('Cache.duration'))) {
    Cache::config('default', array('duration' => $duration));
}

/**
 * TimeZone config
 */
if (($timeZone = Configure::read('Datetime.timeZone'))) {
    date_default_timezone_set($timeZone);
}

/**
 * Log info
 */
if (!defined('LOG_EVENT')) {
    define('LOG_EVENT', 'event');
}
if (!defined('LOG_LOGIN')) {
    define('LOG_LOGIN', 'login');
}
if (!defined('LOG_CREATED')) {
    define('LOG_CREATED', 'created');
}
if (!defined('LOG_UPDATED')) {
    define('LOG_UPDATED', 'updated');
}
if (!defined('LOG_DELETED')) {
    define('LOG_DELETED', 'deleted');
}

$logging = Configure::read('Logging');
if (!empty($logging['enabled'])) {
    CakeLog::config('default', array_merge($logging, array('engine' => 'DatabaseLog')));
} else {
    CakeLog::config('default', array('engine' => 'NoLog'));
}
/**
 * Load modules
 */
$modules = Configure::read('Modules');
if (empty($modules) || !is_array($modules)) {
    throw new ConfigureException(
            __d('debug', 'System error , Config of system modules is missing or corrupted.')
    );
}
foreach ($modules as $module => $moduleConfig) {
    if (CakePlugin::loaded($module) === false) {
        CakePlugin::load($module, $moduleConfig);
    }
}
unset($modules, $module, $moduleConfig, $logging, $duration, $timeZone);
?>